import Vue from 'vue'
import VueRouter from 'vue-router'
import Shopping from '../components/Shopping.vue'
import Home from '../components/Home'
import About from '../components/About'
import Profile from '../components/Profile'
import Hot from '../components/Home/Hot.vue'
import News from '../components/Home/News.vue'

Vue.use(VueRouter);

const routes = [
  {
    path:'/',
    redirect:'/home'
  },
  {
    path:'/home',
    name:'home',
    component:Home,
    meta:{
      title:'首页'
    },
    children:[
      {
        path: '/',
        redirect:'hot'
      },
      {
        path:'hot',//子路由不要加/
        name:'Hot',
        meta:{
          title:'今日头条'
        },
        component:Hot
      },
      {
        path:'news',//子路由不要加/
        name:'News',
        meta:{
          title:'新闻'
        },
        component:News
      }
    ]
  },
  {
    path:'/about',
    meta:{
      title:'关于'
    },
    component:About,
    beforeEnter:(to,from,next) =>{
      // console.log("profile beforeEnter", from, to);
      next();
    }
  },
  {
    path: '/profile/:userId',
    component:Profile,
    meta:{
      title:'我的'
    },
  },
  {
    path:'/shopping',
    component:Shopping,
    meta:{
      title:'购物车'
    },
  }
]


export default new VueRouter({
  routes,
  mode:'history',
  linkActiveClass:'show'
});
//全局导航守卫
